package com.kuang.config;

import com.kuang.handler.AuthorizationInterceptor;
import com.kuang.handler.TokenInterceptor;
import com.kuang.handler.VersionHandlerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//可以使用自定义类扩展MVC的功能
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Bean
    public VersionHandlerInterceptor getVersionHandlerInterceptor() {
        return new VersionHandlerInterceptor();
    }

    // 拦截器注册
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 1：对所有的请求都进行拦截处理增加版本号处理
        registry.addInterceptor(getVersionHandlerInterceptor()).addPathPatterns("/**");
     //   registry.addInterceptor(getAuthorizationInterceptor()).addPathPatterns("/api/**");
   //    registry.addInterceptor(getTokenInterceptor()).addPathPatterns("/api/**");
    }

    @Bean
    public AuthorizationInterceptor getAuthorizationInterceptor(){
        return new AuthorizationInterceptor();
    }

    @Bean
    public TokenInterceptor getTokenInterceptor(){
        return new TokenInterceptor();
    }

}